package com.example.hyw.szysteam.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.NumberPicker;

import com.example.hyw.szysteam.R;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

/**
 * Created by HYW on 2018/6/11.
 */

public class PracticeOptionActivity extends AppCompatActivity implements NumberPicker.Formatter{
    QMUITopBar mTopBar;
    NumberPicker optionNumber;
    NumberPicker optionOperator;
    NumberPicker optionRange;
    QMUIRoundButton begin;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_practiceoption);
        initTopBar();
        initView();
    }

    private void initView(){
        optionNumber=findViewById(R.id.option_number);
        optionOperator=findViewById(R.id.option_operator);
        optionRange=findViewById(R.id.option_range);
        begin=findViewById(R.id.go_practice);
        optionNumber.setFormatter(this);
        optionOperator.setFormatter(this);
        optionRange.setFormatter(this);
        optionNumber.setMaxValue(100);
        optionNumber.setMinValue(10);
        optionOperator.setMinValue(2);
        optionOperator.setMaxValue(10);
        optionRange.setMaxValue(100);
        optionRange.setMinValue(10);
        begin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("type",1);
                bundle.putInt("number",optionNumber.getValue());
                bundle.putInt("operator",optionOperator.getValue());
                bundle.putInt("range",optionRange.getValue());
                Intent intent=new Intent(PracticeOptionActivity.this,PracticeActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
                finish();
            }
        });
    }

    @Override
    public String format(int i) {
        String tmpstr=String.valueOf(i);
        return tmpstr;
    }

    private void initTopBar(){
        mTopBar=findViewById(R.id.topbar);
        mTopBar.setTitle("选项").setTextColor(getResources().getColor(R.color.myWhite));
        mTopBar.addLeftImageButton(R.drawable.ic_left,R.id.left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

}
